#include <iostream>

using std::cout;
using std::endl;


//this指针：代表的是当前对象
//this指针：作为成员函数的第一个隐含参数而存在的

class Point
{
public:
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int,int)" << endl;
    }

    Point(const Point & rhs)
    : _ix(rhs._ix)
    , _iy(rhs._iy)
    {
        cout << "Point(const Point&)" << endl;
        cout << this->_ix << endl;
    }

    //如果不显式定义，系统会自动提供一个赋值运算符函数
    Point & operator=(const Point & rhs)
    {
        cout << "operator=(const Point&)" << endl;
        this->_ix = rhs._ix;
        this->_iy = rhs._iy;

        return *this;
    }

    ~Point() {
        cout << "~Point()" << endl;
    }

    //this指针在编译时会自动添加
    void print(/*   Point *  const this     */) 
    {
        //this = 0x1000;//error, 不能改变指向
        cout << "(" << this->_ix 
             << "," << this->_iy << ")" << endl;
    }

private:
    int _ix;
    int _iy;
};


int test0()
{
    int a = 1, b = 2;
    &(a = b);// 返回的是a本身
    printf("&a: %p\n", &a);
    printf("&(a = b): %p\n", &(a = b));
    cout << (a = b) << endl;

    Point pt1(10, 11);
    Point pt2(20, 21);

    //执行赋值操作,这里会调用赋值运算符函数
    pt1 = pt2;

    cout << "pt1:";
    pt1.print();

    cout << "pt2:";
    pt2.print();


    return 0;
}

int main()
{
    test0();
    return 0;
}

